package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.CrmOperationRecordAddDTO;
import org.jsola.hr.dto.CrmOperationRecordUpdateDTO;
import org.jsola.hr.entity.CrmOperationRecordDO;
import org.jsola.hr.query.CrmOperationRecordQuery;
import org.jsola.hr.service.ICrmOperationRecordService;
import org.jsola.hr.vo.CrmOperationRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 操作记录表
 *
 * @author zhr
 */
@Component
public class CrmOperationRecordTestHelper extends BaseTestHelper {
    
    @Autowired
    private ICrmOperationRecordService crmOperationRecordService;

    /**
     * 生成add测试数据
     * @return CrmOperationRecordAddDTO
     */
    public CrmOperationRecordAddDTO getCrmOperationRecordAddDTO(){
        CrmOperationRecordAddDTO crmOperationRecordAddDTO = new CrmOperationRecordAddDTO();
        crmOperationRecordAddDTO.setCustomerId(getRandomValue("varchar",32));
        crmOperationRecordAddDTO.setRecordInfo(getRandomValue("varchar",100));
        crmOperationRecordAddDTO.setOperationType(SafeKit.getInteger(getRandomValue("int",5)));
        crmOperationRecordAddDTO.setOperationName(getRandomValue("varchar",32));
        return crmOperationRecordAddDTO;
    }


    /**
     * 生成update测试数据
     * @return CrmOperationRecordUpdateDTO
     */
    public CrmOperationRecordUpdateDTO getCrmOperationRecordUpdateDTO(CrmOperationRecordVO crmOperationRecordVO){
        return crmOperationRecordService.selectDOById(crmOperationRecordVO.getId(), SITE_ID).to(CrmOperationRecordUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return CrmOperationRecordQuery
     */
    public CrmOperationRecordQuery getCrmOperationRecordQuery() {
        CrmOperationRecordQuery crmOperationRecordQuery = new CrmOperationRecordQuery();
        List<CrmOperationRecordDO> crmOperationRecordDOList = crmOperationRecordService.list(new CrmOperationRecordDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(crmOperationRecordDOList)) {
            CrmOperationRecordDO crmOperationRecordDO = crmOperationRecordDOList.get(0);
            crmOperationRecordQuery = crmOperationRecordDO.to(CrmOperationRecordQuery.class);
        }
        return crmOperationRecordQuery;
    }

    /**
     * 保存示例
     * @return CrmOperationRecordVO
     */
    public CrmOperationRecordVO saveCrmOperationRecordExample(){
        CrmOperationRecordAddDTO addDTO = this.getCrmOperationRecordAddDTO();
        CrmOperationRecordVO crmOperationRecordVO = crmOperationRecordService.save(addDTO,buildTokenUser());
        return crmOperationRecordVO;
    }


}

